<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>

<%@page import="com.lovo.bbs.vo.*,com.lovo.bbs.bo.*,java.util.*"%>

<%
	//请求页
	String queryPages = (String) request.getParameter("queryPage");
	if (queryPages == null || "".equals(queryPages)
			|| "0".equals(queryPages)) {
		queryPages = "1";
	}
	int queryPage = Integer.parseInt(queryPages);

	//用户列表(数据库分页)
	UserInfoBo userInfoBo =  new UserInfoBo();
	ArrayList<UserInfoVo> userList = userInfoBo.getUsers(queryPage);
	//用户总数
	int pageCount = userInfoBo.getUserNum();
	int pageNum = (pageCount % 20 == 0) ? (pageCount / 20)
			: (pageCount / 20 + 1);
	Iterator it;
%>
<html>
	<head>
		<link href="../../../css/admin.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="../../../js/wbs_admin.js"></script>
		
		<script type="text/javascript">
		
		function preQuery(){
			document.frmMain.action="userManageQueryPage.jsp";
			document.frmMain.submit();
		}
		function preModify(userid,username,usergroupid,bday,postnum,email,credits){
			document.frmMain.userid.value=userid;
			document.frmMain.username.value=username;
			document.frmMain.usergroupid.value=usergroupid;
			document.frmMain.bday.value=bday;
			document.frmMain.postnum.value=postnum;
			document.frmMain.email.value=email;
			document.frmMain.credits.value=credits;
			
			document.frmMain.opType.value=2;
			document.frmMain.action="userManageUpdatePage.jsp";
			document.frmMain.submit();
		}
		function preDelete(userid,username,usergroupid,bday,postnum,email,credits){
			document.frmMain.userid.value=userid;
			document.frmMain.username.value=username;
			document.frmMain.usergroupid.value=usergroupid;
			document.frmMain.bday.value=bday;
			document.frmMain.postnum.value=postnum;
			document.frmMain.email.value=email;
			document.frmMain.credits.value=credits;
			
			document.frmMain.opType.value=3;
			document.frmMain.action="userManageUpdatePage.jsp";
			document.frmMain.submit();
		}
		</script>
	</head>
	<body>
		<form name="frmMain" method="POST">
			<table class="navigation" style="width: 98%" align="center">
				<tr>
					<td>
						当前位置: 用户管理
					</td>
				</tr>
			</table>
			<table border="0" cellspacing="0" cellpadding="0" style="width: 98%"
				align="center">
				<tr>
					<td>
						<table width="100%" border="0" cellspacing="0" cellpadding="4">
							<tr>
								<td id="content_bar">
									<a class="content_total">用户总数: <%=pageCount%> ,第<%=queryPage%>页
										总<%=pageNum%>页 </a>
									<%
										for (int i = 1; i <= pageNum; i++) {
											if (i == queryPage) {
									%>
									<a class="content_pasges_c"><%=i%> </a>
									<%
										} else {
									%>
									<A class="content_pasges_a"
										href="userManageQueryPage.jsp?queryPage=<%=i%>"><%=i%> </A>
									<%
										}
										}
									%>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td>
						<table border="0" cellspacing="1" cellpadding="4"
							class="tableborder"
							style="background-color: #CCFFFF; border: #99FFCC 0px solid">
							<tr class="header">
								<td width="8%">
									用户名
								</td>

								<td>
									用户组
								</td>
								<td width="6%">
									生日
								</td>
								<td>
									发表数
								</td>
								<td>
									email
								</td>
								<td>
									积分
								</td>
								<td width="10%">
									操作
								</td>
							</tr>
							<%
								int userid, umanageid, postnum, credits;
								String username, bday, email;
								if (userList == null) {
									userList = new ArrayList<UserInfoVo>();
								}
								it = userList.iterator();
								if (it != null) {
									while (it.hasNext()) {
										UserInfoVo userData = (UserInfoVo) (it.next());
										userid = userData.getUserId();

										//用户类型
										umanageid = userData.getType();
										postnum = userData.getTopicNum();
										credits = userData.getScore();

										username = userData.getUserName();
										bday = userData.getBirthday();
										email = userData.getEmail();
							%>
							<tr class="row">
								<td>
									<%=username%>
								</td>

								<td>
									<%
										if (umanageid == 0) {
									%>
									<%="用户"%>
									<%
										} else if (umanageid == 1) {
									%>
									<%="版主"%>
									<%
										} else if (umanageid == 2) {
									%>
									<%="管理员"%>
									<%
										}
									%>
								</td>
								<td>
									<%=bday%>
								</td>
								<td>
									<%=postnum%>
								</td>
								<td>
									<%=email%>
								</td>
								<td>
									<%=credits%>
								</td>
								<td>
									<input type="button" value="修改" class="button"
										onclick="preModify('<%=userid%>','<%=username%>','<%=umanageid%>','<%=bday%>','<%=postnum%>','<%=email%>','<%=credits%>')")">
									<input type="button" value="删除" class="button"
										style="color: #ff0000;"
										onclick="preDelete('<%=userid%>','<%=username%>','<%=umanageid%>','<%=bday%>','<%=postnum%>','<%=email%>','<%=credits%>')">
								</td>
							</tr>
							<%
								}
								}
							%>
						</table>
					</td>
				</tr>
			</table>
			<br>
			<input type="hidden" name="userid" value="">
			<input type="hidden" name="username" value="">
			<input type="hidden" name="bday" value="">
			<input type="hidden" name="email" value="">

			<input type="hidden" name="postnum" value="">
			<input type="hidden" name="credits" value="">
			<input type="hidden" name="usergroupid" value="">

			<input type="hidden" name="opType" value="">

			<input type="hidden" name="queryPage" value="<%=queryPage%>">
		</form>
	</body>
</html>
